package org.neurone.action.userspace;

import java.util.ArrayList;
import java.util.List;

import org.neurone.action.BaseActionSupport;
import org.neurone.domain.Application;
import org.neurone.domain.UserInfo;
import org.neurone.domain.UserDetailInfo;
import org.neurone.session.SessionHive;
import org.neurone.userspace.userinfo.UserMgr;
import org.neurone.userspace.userinfo.impl.UserFaceLocalFactory;

public class HomeAction extends BaseActionSupport {
	private String appKey;
	private String fromURL;
	private List<Application> appList;
	private UserInfo userInfo;
	private List<UserDetailInfo> userDetailInfoList;
	private UserFaceLocalFactory userFaceFactory;
	private UserMgr userMgr;
	
	
	public String getAppKey() {
		return appKey;
	}

	public String getFromURL() {
		return fromURL;
	}

	public SessionHive getSessionHive() {
		return sessionHive;
	}

	public List<Application> getAppList() {
		return appList;
	}

	public UserInfo getUserInfo() {
		return userInfo;
	}

	public void setAppKey(String appKey) {
		this.appKey = appKey;
	}

	public void setFromURL(String fromURL) {
		this.fromURL = fromURL;
	}

	public void setSessionHive(SessionHive sessionHive) {
		this.sessionHive = sessionHive;
	}

	public void setAppList(List<Application> appList) {
		this.appList = appList;
	}

	public void setUserInfo(UserInfo userInfo) {
		this.userInfo = userInfo;
	}
	
	

	public List<UserDetailInfo> getUserDetailInfoList() {
		return userDetailInfoList;
	}

	public void setUserDetailInfoList(List<UserDetailInfo> userDetailInfoList) {
		this.userDetailInfoList = userDetailInfoList;
	}

	public UserFaceLocalFactory getUserFaceFactory() {
		return userFaceFactory;
	}

	public UserMgr getUserMgr() {
		return userMgr;
	}

	public void setUserFaceFactory(UserFaceLocalFactory userFaceFactory) {
		this.userFaceFactory = userFaceFactory;
	}

	public void setUserMgr(UserMgr userMgr) {
		this.userMgr = userMgr;
	}

	public String showHome()
	{
		String userName = checkNowSession();
		if(userName != null) 
		{
			UserInfo user = this.userMgr.find(userName);
			if(user != null)
			{
				Long userID = user.getUserID();
				this.userInfo = this.userFaceFactory.getNewUserFace(userID);
				this.userDetailInfoList = this.userInfo.getUserDetailInfoList();
				this.appList = new ArrayList<Application>( this.userInfo.getAssignedApplicationList());
				return success("");
			}		
			else
			{
				return LOGIN;
			}
		}
		else
		{
			return LOGIN;
		}
	}

}
